package com.fzhucc.modules.sciPersonnelInfo.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciExpertConsultationConfigEditDto;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciExpertConsultationConfigQueryCriteria;
import com.fzhucc.modules.sciPersonnelInfo.service.SciExpertConsultationConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author yyg
* @date 2023-10-20
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "劳模:线上咨询配置")
@RequestMapping("/api/sciExpertConsultationConfig")
public class SciExpertConsultationConfigController {

    private final SciExpertConsultationConfigService expertConsultationConfigService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sciExpertConsultationConfig:list')")
    public void exportExpertConsultationConfig(HttpServletResponse response, SciExpertConsultationConfigQueryCriteria criteria) throws IOException {
        expertConsultationConfigService.download(expertConsultationConfigService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询专家线上咨询配置")
    @ApiOperation("查询专家线上咨询配置")
    @PreAuthorize("@el.check('sciExpertConsultationConfig:list')")
    public ResponseEntity<Object> queryExpertConsultationConfig(SciExpertConsultationConfigQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(expertConsultationConfigService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @DeleteMapping
    @Log("删除专家线上咨询配置")
    @ApiOperation("删除专家线上咨询配置")
    @PreAuthorize("@el.check('sciExpertConsultationConfig:del')")
    public ResponseEntity<Object> deleteExpertConsultationConfig(@RequestBody Integer[] ids) {
        expertConsultationConfigService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping(value = "/saveList")
    @Log("专家线上咨询配置操作")
    @ApiOperation("专家线上咨询配置操作")
    public ResponseEntity<Object> editExpertConsultationConfig(@Validated @RequestBody SciExpertConsultationConfigEditDto resources){
        return new ResponseEntity<>(expertConsultationConfigService.saveList(resources),HttpStatus.NO_CONTENT);
    }
}